import { formatFileSize, isDefinedGlobally} from "./utils";
import { Validator } from "vee-validate";

const messages = {
  after: (field, [target]) => ` ${field}必须在${target}之后`,
  alpha_dash: field => ` ${field}能够包含字母数字字符，包括破折号、下划线`,
  alpha_num: field => `${field} 只能包含字母数字字符.`,
  alpha_spaces: field => ` ${field} 只能包含字母字符，包括空格.`,
  alpha: field => ` ${field} 只能包含字母字符.`,
  before: (field, [target]) => ` ${field} 必须在${target} 之前.`,
  between: (field, [min, max]) => ` ${field} 必须在${min} ${max}之间.`,
  // confirmed: (field, [confirmedField]) => ` ${field} 不能和${confirmedField}匹配.`,
  confirmed: (field, [confirmedField]) => `两次密码输入需要相同`,
  date_between: (field, [min, max]) => ` ${field}必须在${min}和${max}之间.`,
  date_format: (field, [format]) => ` ${field}必须在在${format}格式中.`,
  decimal: (field, [decimals] = ["*"]) =>
    ` ${field} 必须是数字的而且能够包含${
      decimals === "*" ? "" : decimals
    } 小数点.`,
  digits: (field, [length]) => ` ${field} 必须是数字，且精确到 ${length}数`,
  dimensions: (field, [width, height]) =>
    ` ${field}必须是 ${width} 像素到 ${height} 像素.`,
  email: field => ` ${field} 必须是有效的邮箱.`,
  ext: field => ` ${field} 必须是有效的文件.`,
  image: field => ` ${field} 必须是图片.`,
  in: field => ` ${field} 必须是一个有效值.`,
  ip: field => ` ${field} 必须是一个有效的地址.`,
  max: (field, [length]) => ` ${field} 不能大于${length}字符.`,
  mimes: field => ` ${field} 必须是有效的文件类型.`,
  min: (field, [length]) => ` ${field} 必须至少有 ${length} 字符.`,
  not_in: field => ` ${field}必须是一个有效值.`,
  numeric: field => ` ${field} 只能包含数字字符.`,
  regex: field => ` ${field} 格式无效.`,
  required: field => `${field}是一个必填项`,
  size: (field, [size]) => ` ${field} 必须小于 ${formatFileSize(size)}.`,
  url: field => ` ${field}不是有效的url.`,
  mobile: field => `请输入正确的手机号码`,
};

/* Validator.extend('mobile', {
    messages: {
      en:field => `${field}必须是11位手机号码`,
    },
    validate: value => {
      return value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
    }
}); */

const locale = {
    name: 'zh_CN',
    messages,
    attributes: {}
};

if (isDefinedGlobally()) {
    VeeValidate.Validator.addLocale(locale);
}
const isMobile = {
  messages: {
    en: (field, args) => field + "必须是11位手机号码"
  },
  validate: (value, args) => {
    return (
      value.length == 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/.test(value)
      // value.length == 11 && /^[1][3,4,5,7,8][0-9]{9}$/.test(value)
    );
  }
};
Validator.extend("mobile", isMobile);

export default locale;